package com.thinkingstar.iads.uruleExample.action;

import com.bstek.urule.runtime.KnowledgeSession;
import com.thinkingstar.iads.test.urule.controller.RuleTool;
import com.thinkingstar.iads.uruleExample.entity.Customer;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;

import java.util.List;
import java.util.Map;

/**
 * 可引用条件 规则 测试
 * */
@At("/refrule")
@IocBean
public class RefRuleTest {

    @At("/test")
    @Ok("json:full")
    public List<Map> test(){
        Customer c1 = new Customer();
        c1.setLevel(12);
        c1.setMarried(false);
        c1.setName("张三");

        Customer c2 = new Customer();
        c2.setLevel(9);
        c2.setMarried(false);
        c2.setName("李四");

        Customer c3 = new Customer();
        c3.setLevel(0);
        c3.setAge(10);
        c3.setName("赵二");

        Customer c4 = new Customer();
        c4.setAge(11);
        c4.setLevel(0);
        c4.setName("王五");

        Customer c5 = new Customer();
        c5.setLevel(0);
        c5.setAge(15);
        c5.setName("钱六");

        KnowledgeSession knowledgeSession = RuleTool.getSessionFactory("testExample/ref_rule");
        knowledgeSession.insert(c1);
        knowledgeSession.insert(c2);
        knowledgeSession.insert(c3);
        knowledgeSession.insert(c4);
        knowledgeSession.insert(c5);

        knowledgeSession.fireRules();
        List<Map> list = (List<Map>) knowledgeSession.getParameter("list");
        return list;

    }
}
